import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.xssf.usermodel.XSSFCell;
import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.junit.Test;

import java.io.FileOutputStream;

public class POITest {
    //写数据
    @Test
    public void testi() throws Exception {
        XSSFWorkbook workbook = new XSSFWorkbook();
        XSSFSheet sheet = workbook.createSheet("sheet1");
        //创建行 0为第一行
        XSSFRow row = sheet.createRow(0);
        //创建单元格
        row.createCell(0).setCellValue("编号");
        row.createCell(1).setCellValue("名称");
        row.createCell(2).setCellValue("年龄");
        XSSFRow row2 = sheet.createRow(1);
        row2.createCell(0).setCellValue("1");
        row2.createCell(1).setCellValue("我");
        row2.createCell(2).setCellValue("21");
        //通过输出流将work对象下载到磁盘
        FileOutputStream out = new FileOutputStream("D:\\00\\hello.xlsx");
        workbook.write(out);
        out.flush();
        out.close();
        workbook.close();
    }
    //打东西//打什么东西我也步知道//老蒋光喊打我怎么知道打什么
    //那我就打一首诗吧
    //四十年来家国，三千里地山河，风格龙楼连霄汉，玉树琼枝做烟罗，几曾识干戈，一旦归为臣虏，沈腰潘鬓消磨，最是仓皇辞庙日，叫坊尤奏别离哥，垂泪对宫娥。
    //读数据
    @Test
    public void testo() throws Exception {
        //创建工作簿对象
       XSSFWorkbook workbook = new XSSFWorkbook("D:\\00\\hello.xlsx");
       //获取表
        XSSFSheet sheet = workbook.getSheetAt(0);
        //遍历工作表
        for (Row row : sheet) {
            //遍历行对象格对
            for (Cell cell : row) {
                String value = cell.getStringCellValue();
                System.out.println(value);
            }
        }
        workbook.close();
    }
}
